
package com.example.vdmtest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.util.Log;

import com.vivo.ic.dm.Constants;

import android.net.NetworkInfo;
import android.widget.Toast;

/**
 * Receives system broadcasts (boot, network connectivity)
 */
public class NetworkReceiver extends BroadcastReceiver {
    private static final String TAG = Constants.PRE_TAG + "NetworkReceiver";

    @Override
    public void onReceive(final Context context, final Intent intent) {

        final String action = intent.getAction();
        Log.i(TAG, "onReceive action: " + action);

        ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = connManager.getActiveNetworkInfo();
        if (netInfo == null) {
            Toast.makeText(context, R.string.no_available_net, Toast.LENGTH_SHORT).show();
        } else if (netInfo.isConnected()) {
            if (netInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                Toast.makeText(context, R.string.mobile_is_available, Toast.LENGTH_SHORT).show();
            }
            if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                Toast.makeText(context, R.string.wifi_is_available, Toast.LENGTH_SHORT).show();
            }

        }


    }
}
